package cn.tedu.egmvc1.controller;

import cn.tedu.egmvc1.pojo.entity.User;
import cn.tedu.egmvc1.pojo.vo.UserIdVO1;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@Controller
public class UserController {
    /**
     * 添加用户
     *
     * @return userIdVO1
     */
    @RequestMapping("/v1/users/insert")
    @ResponseBody()
    public String addUser(UserIdVO1 userIdVO1) {
        userIdVO1.setUsername(userIdVO1.getUsername());
        userIdVO1.setPassword(userIdVO1.getPassword());
        userIdVO1.setNickname(userIdVO1.getNickname());
        System.out.println(userIdVO1);
        return "添加用户成功";
    }


    /**
     * 删除用户
     *
     * @return id
     */
    @RequestMapping("/v1/users/delete")
    @ResponseBody()
    public String deleteUser(HttpServletRequest request) {
        String id = request.getParameter("id");
        return "删除用户成功" + "用户id为：" + id;
    }


    /**
     * 查询用户
     *
     * @return
     */

    @RequestMapping("/v1/users/userList")
    @ResponseBody()
    public String selectUser() {
        return "查询用户成功";
    }

    /**
     * 修改用户
     *
     * @param user
     * @return
     */
    @RequestMapping("/v1/users/update")
    @ResponseBody()
    public String updateUser(User user) {
        user.setId(user.getId());
        user.setUsername(user.getUsername());
        user.setPassword(user.getPassword());
        user.setNickname(user.getNickname());
        System.out.println(user);
        return "修改用户成功";
    }

}



